package com.etogc.groupchat.login.ui;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;

import com.etogc.groupchat.R;
import com.etogc.groupchat.common.CommonSp;
import com.etogc.groupchat.main.MainActivity;
import com.etogc.util.IntentHelper;
import com.etogc.util.SpUtil;

public class SplashActivity extends AppCompatActivity {

    private android.os.Handler handler = new android.os.Handler();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_splash);
        handler.postDelayed(new Runnable() {
            @Override
            public void run() {
                goToMain();
            }
        }, 800);
    }

    private void goToMain() {
        if (hasToken()) {
            IntentHelper.jump(this, MainActivity.class);
        } else {
            IntentHelper.jump(this, LoginSelectActivity.class);
        }
        finish();
    }

    private boolean hasToken() {
        if (null == CommonSp.getToken() || "".equals(CommonSp.getToken())) {
            return false;
        }
        return true;
    }
}
